package com.iqiyi.pps.epg.core.dao.carousel;

import com.iqiyi.pps.epg.core.dao.base.BaseDao;
import com.iqiyi.pps.epg.core.dao.base.PropertyFilter;
import com.iqiyi.pps.epg.core.model.carousel.AutoCarouselEpisodeLibrary;
import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Lemuel on 2016/6/28.
 */
@Component
public class AutoCarouselEpisodeLibraryDao extends BaseDao<AutoCarouselEpisodeLibrary> implements IIndexSortDao<AutoCarouselEpisodeLibrary>{
    public List<AutoCarouselEpisodeLibrary> find(List<PropertyFilter> filters, int maxSize) {
        Criterion[] criterions = buildCriterionByPropertyFilter(filters);
        Criteria criteria = createCriteria(criterions);
        criteria.setMaxResults(maxSize);
        return criteria.list();
    }

    public List<AutoCarouselEpisodeLibrary> getListByFatherId(long channelId) {
        Criteria criteria = this.createCriteria();
        criteria.add(Restrictions.gt("status", AutoCarouselEpisodeLibrary.STATUS_DELETE));
        criteria.add(Restrictions.eq("fatherId", channelId));
        criteria.addOrder(Order.asc("execIndex"));
        criteria.addOrder(Order.desc("lastSortTime"));
        return this.find(criteria);
    }

    public AutoCarouselEpisodeLibrary getById(long entityId) {
        return this.findUniqueBy("id", entityId);
    }
    public void saveEntity( AutoCarouselEpisodeLibrary entity){
       this.save(entity);
    }
}
